package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import information.AbstractInformation;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToggleButton;

import table.AbstractTable;



@SuppressWarnings("serial")
public class SelectedTableController extends AbstractController {

	protected final AbstractTable vinylTable;
	protected final AbstractTable memberTable;
	protected final AbstractTable personTable;
	protected final AbstractTable storageTable;
	protected final AbstractInformation statusInformation;

	public SelectedTableController(
			AbstractTable vinylTable, AbstractTable memberTable, AbstractTable personTable, AbstractTable storageTable,
			AbstractInformation statusInformation, 	
			ButtonGroup buttonGroup, JPanel infoPane) {
		
		super(infoPane);
		
		this.vinylTable = vinylTable;
		this.memberTable = memberTable;
		this.personTable = personTable;
		this.storageTable = storageTable;
		
		this.statusInformation = statusInformation;
		
		JToggleButton vinylButton = new JToggleButton("Vinyl");
		vinylButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				SelectedTableController.this.select(SelectedTableController.this.vinylTable, SelectedTableController.this.statusInformation);
			}
		});
		
		JToggleButton storageButton = new JToggleButton("Plassering");
		storageButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				SelectedTableController.this.select(SelectedTableController.this.storageTable, SelectedTableController.this.statusInformation);
			}
		});
		
		JToggleButton memberButton = new JToggleButton("Medlem");
		memberButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				SelectedTableController.this.select(SelectedTableController.this.memberTable, SelectedTableController.this.statusInformation);
			}
		});
		
		JToggleButton personButton = new JToggleButton("Person");
		personButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				SelectedTableController.this.select(SelectedTableController.this.personTable, SelectedTableController.this.statusInformation);
			}
		});
		
		buttonGroup.add(vinylButton);
		buttonGroup.add(storageButton);
		buttonGroup.add(memberButton);
		buttonGroup.add(personButton);
		
		this.add(vinylButton);
		this.add(storageButton);
		this.add(memberButton);
		this.add(personButton);
		
		JButton deleteSelected = new JButton("Delete Selected");
		deleteSelected.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				SelectedTableController.this.getCurrentView().deleteSelectedRowsFromDatabase();
			}
		});
		
		this.add(deleteSelected);
		
	}

}
